<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>加好友历史记录</title>
    <link rel="stylesheet" href="../assets/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../assets/style/admin.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <script src="../assets/layui/layui.js"></script>
    <script src="../assets/js/common.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script src="../common/header.js"></script>
    <!-- 内容主体区域 -->
    <div id="LAY_app_body">
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            朋友圈素材管理&nbsp;&nbsp;
                            <a class="layui-btn layui-btn-sm" href="edit.html">添加</a>
                        </div>
                        <div class="layui-card-body">
                            <form class="layui-form" action="">
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <input type="text" name="title" lay-verify="title" placeholder="内容" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <div class="layui-input-inline">
                                        <select id="group_id1" style="layui-input-inline" onchange="reloadList()">
                                            <option value="1">启用的</option>
                                            <option value="0">禁用的</option>
                                            <option value="9">全部</option>
                                        </select>
                                    </div>
                                </div>
                                <button class="layui-btn layui-btn-xs" onclick="reloadList();">搜索</button>
                                <button class="layui-btn layui-btn-xs layui-btn-primary" onclick="reloadList(true);">重置</button>
                            </form>
                            <table id="LAY-list-manage" lay-filter="LAY-list-manage"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        var reloadList;
        layui.use(['element', 'table', 'form', 'laydate'], function(){
            var $ = layui.$
                ,table = layui.table
                ,laydate = layui.laydate
                ,form = layui.form
                ,element = layui.element;

            element.init();

            var status = $('#status').find("option:selected").val();
            table.render({
                elem: '#LAY-list-manage'
//            ,height: 315
                ,where: {//设定异步数据接口的额外参数
                    status: status
                }
                ,url: '/sns_post/list_data' //数据接口
                ,page: true //开启分页
                ,cols: [[ //表头
                    {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
                    ,{field: 'created_at', title: '创建时间', width:170}
                    ,{field: 'type', title: '类型', width:100, templet: '#typeTpl'}
                    ,{field: 'content', title: '内容'}
//                ,{field: 'status', title: '状态', width:100, templet: '#statusTpl', unresize: true}
                    ,{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'}
                ]]
                ,title: '列表'
//            ,toolbar: '#toolbarDemo'
//            ,defaultToolbar: ['filter']
            });

            //监听工具条
            table.on('tool(LAY-list-manage)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象

                if(layEvent === 'detail'){ //查看
                    //do somehing
                } else if(layEvent === 'del'){ //删除

                } else if(layEvent === 'edit'){ //编辑
                    //do something
                }
            });

            reloadList = function (reset) {
                if (reset==true) {
                    $('#status').find('option:first').attr("selected",false);
                    $('#status').find('option:first').attr("selected",true);
                    $('#search').val('');
                }
                var status = $('#status').find("option:selected").val();
                var search = $('#search').val();
                table.reload('LAY-list-manage', {
                    where: { //设定异步数据接口的额外参数，任意设
                        status: status,
                        search: search
                    }
                    ,page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            };
        });

    </script>
    <script type="text/html" id="typeTpl">
        {{# if(d.type == 1){ }}
        <span style="color: black;">文字</span>
        {{# } else if(d.type == 2){ }}
        <span style="color: orange;">图文</span>
        {{# } else if(d.type == 3){ }}
        <span style="color: green;">视频</span>
        {{# } else if(d.type == 4){ }}
        <span style="color: blue;">分享</span>
        {{# } }}
    </script>
    <script type="text/html" id="statusTpl">
        {{# if(d.status == 1){ }}
        <span style="color: green;">启用</span>
        {{# } else if(d.status == 0){ }}
        <span style="color: red;">禁用</span>
        {{# } }}
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-sm" href="/sns_post/edit/{{d.id}}">编辑</a>
        <a class="layui-btn layui-btn-normal layui-btn-sm" href="/sns_post_plan/batch/{{d.id}}">发布</a>
    </script>
</div>
</body>
</html>
